# 数据重塑

city <- c("Tampa","Seattle","Hartford","Denver");
state <-c("FL","WA","CT","CO");
zipcode <- c(33602,98104,06161,80294);

#使用cbind()函数连接多个向量创建数据帧
addresses <- cbind( city,state,zipcode);
print(addresses)

# data frame 数据格式创建
new.address <- data.frame(
    city = c("Lowry","Charlotte"),
    state = c("CO","FL"),
    zipcode = c("80230","33949")
    
)
print( new.address );

# 使用rbind()函数连接data frame和数据帧
all.address <- rbind(addresses,new.address);
print( all.address );

# 
library(MASS);
merge.Pima<- merge(
    x=Pima.te,
    y=Pima.tr,
    by.x = c("bp","bmi"),
    by.y = c("bp","bmi")
)
print(merge.Pima);
nrow( merge.Pima);

# 
library(MASS);
library(reshape2);
# 使用melt()拆分数据
molten.ships = melt(ships,id.vars = c("type","year"),variable.name = "variable",value.name = "value");
print( molten.ships);

# 使用cast()函数进行数据的内部运算
recasted.ship <- cast(molten.ships,type+year~variable,sum);
print( recasted.ship );



